﻿using System;
using System.Globalization;
using Cesave.Application.Permisos.Settings;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.Presentation.Permisos.WinForms.Client.Resources;
using Cesave.Presentation.Permisos.WinForms.Client.ViewModelBase;
using Cesave.Presentation.Permisos.WinForms.Client.Views.Main;

namespace Cesave.Presentation.Permisos.WinForms.Client.ViewModels.Main
{
    public partial class MainViewModel
        : ObservableObject
    {
        #region Private properties

        private MainView _view;
        private IPUSSettings _pusSettings;

        #endregion

        #region Public properties



        #endregion

        #region Constructor

        public MainViewModel(MainView view)
        {
            if (view == (MainView)null)
                throw new ArgumentNullException("view");
            _pusSettings = IoCFactory.Resolve<IPUSSettings>();
            _view = view;
            WireUpEvents();
        }

        #endregion

        #region Event methods

        private void WireUpEvents()
        {
            PropertyChanged += MainViewModel_PropertyChanged;
            _view.Load += ViewLoad;
            _view.mainToolbarsManager.ToolClick += HandleMenu;
            _view.mainTabbedMdiManager.TabClosing += ClosingView;
        }

        private void ViewLoad(object sender, EventArgs e)
        {
            _view.Text = string.Format(
                CultureInfo.InvariantCulture,
                WindowTitles.MainWindowTitle,
                _pusSettings.Junta.Nombre,
                _pusSettings.Agente.NombreCompleto
            );
        }

        #endregion

        #region Private methods
        #endregion
    }
}
